######################################################################
# Time-stamp: <05/06/16 11:44:41 ostolop>
#
# Package: EP::EPC::Core::Upload
#
# Responsible for processing all data uploads
######################################################################
package EP::EPC::Core::Upload;

use strict;

use EP::EPC::Core::Component;
use base qw ( EP::EPC::Core::Component );

use EP::Common;
use EP::Core::Data::Parser::Factory;

use PDL;
use PDL::IO::FlexRaw;
use PDL::Graphics::PGPLOT;

sub process_component {
   my $self = shift;

   my $data_type = $self->{query}->param ( "upload_data_type" );

   my $parser  = EP::Core::Data::Parser::Factory->create_data_parser ( data_type  => $data_type,
								       query      => $self->{query},
								       caller_epc => $self );

   my $dataset = $parser->parse_data();
   my $metadata_result = $dataset->data->process_metadata ( $self->{session} );

   $self->{session}->status ( "Dataset processed." ) if $dataset;

   die "Failed to create the dataset..." if not $dataset;

   my $process_result = { dataset_name   => $dataset->name,
			  dataset_id     => $dataset->id,
			  src_dataset_id => $dataset->id,
			  dst_dataset_id => $dataset->id
			};

   my %pr = ( %$process_result, %$metadata_result );
   $self->{CD}->{process_result} = \%pr;
   return $self->record_analysis_history ( new_root_dataset => 1 );
#
#   return OK;
}

1;
